<?php

/**
 * 数据统计控制器
 */

namespace App\Http\ManagerApi\Controllers;

use App\Api\BaseClass\Controller;
use App\Http\WechatAuth\Models\User;
use App\Http\WechatAuth\Models\UserCashRequestLog;
use App\Http\WechatAuth\Models\UserIntegralLog;
use Illuminate\Support\Facades\DB;

class InformationCountController extends Controller
{
    /**
     * 用户数据
     */
    public function userCount()
    {
        $data['total_user'] = User::where('is_active',1)->count();
        $data['day_user'] = User::where('is_active',1)->whereDate('updated_at',date('Y-m-d'))->count();
        $w = date('W');
        $data['week_user'] = User::where('is_active',1)->whereRaw('date_format(updated_at,\'%u\') = ?',[$w])->count();
        $data['month_user'] = User::where('is_active',1)->whereYear('updated_at',date('Y'))->whereMonth('updated_at',date('m'))->count();
        return $this->form->datas($data);
    }

    /**
     * 提现数据
     */
    public function cashCount()
    {
        $data['total_money'] = UserCashRequestLog::where('status',1)->sum('changed_integral');
        $data['day_money'] = UserCashRequestLog::where('status',1)->whereDate('updated_at',date('Y-m-d'))->sum('changed_integral');
        $w = date('W');
        $data['week_money'] = UserCashRequestLog::where('status',1)->whereRaw('date_format(updated_at,\'%u\') = ?',[$w])->sum('changed_integral');
        $data['month_money'] = UserCashRequestLog::where('status',1)->whereYear('updated_at',date('Y'))->whereMonth('updated_at',date('m'))->sum('changed_integral');
        return $this->form->datas($data);
    }

    /**
     * 平台金额数据
     */
    public function moneyCount()
    {
        $data['total_money'] = User::where('is_active',1)->sum('integral');
        $data['day_money'] = UserIntegralLog::where('is_finished',1)->whereDate('updated_at',date('Y-m-d'))->sum('changed_integral');
        $w = date('W');
        $data['week_money'] = UserIntegralLog::where('is_finished',1)->whereRaw('date_format(updated_at,\'%u\') = ?',[$w])->sum('changed_integral');
        $data['month_money'] = UserIntegralLog::where('is_finished',1)->whereYear('updated_at',date('Y'))->whereMonth('updated_at',date('m'))->sum('changed_integral');
        return $this->form->datas($data);
    }
    
}